// 时间戳转时间格式
const TimeFormat = function(times) {
	if(!times) {
		return ''
	}
	var time = new Date(times);
	var y = time.getFullYear() < 10?'0' + time.getFullYear():time.getFullYear();
	var m = time.getMonth() + 1 < 10?'0' + (time.getMonth()+1):time.getMonth()+1;
	var d = time.getDate() < 10?'0' + time.getDate():time.getDate();
	var h = time.getHours() < 10?'0' + time.getHours():time.getHours();
	var mm = time.getMinutes() < 10?'0' + time.getMinutes():time.getMinutes();
	var s = time.getSeconds() < 10?'0' + time.getSeconds():time.getSeconds();
	return y +'-'+ m +'-'+ d +' '+ h +':'+ mm +':'+ s ;
}

// 大额数字转个十百千万
const NumberConversion = function(value) {
    const newValue = ['', '', '']
    	let fr = 1000
    	let num = 3
    	let text1 = ''
    	let fm = 1
    	while (value / fr >= 1) {
    		fr *= 10
    		num += 1
    	}
    	if (num <= 4) { // 千
    		newValue[0] = parseInt(value / 1000) + ''
    		newValue[1] = '千'
    	} else if (num <= 8) { // 万
    		text1 = parseInt(num - 4) / 3 > 1 ? '千万' : '万'
    		fm = text1 === '万' ? 10000 : 10000000
    		if (value % fm === 0) {
    			newValue[0] = parseInt(value / fm) + ''
    		} else {
    			newValue[0] = parseFloat(value / fm).toFixed(2) + ''
    		}
    		newValue[1] = text1
    	} else if (num <= 16) { // 亿
    		text1 = (num - 8) / 3 > 1 ? '千亿' : '亿'
    		text1 = (num - 8) / 4 > 1 ? '万亿' : text1
    		text1 = (num - 8) / 7 > 1 ? '千万亿' : text1
    		fm = 1
    		if (text1 === '亿') {
    			fm = 100000000
    		} else if (text1 === '千亿') {
    			fm = 100000000000
    		} else if (text1 === '万亿') {
    			fm = 1000000000000
    		} else if (text1 === '千万亿') {
    			fm = 1000000000000000
    		}
    		if (value % fm === 0) {
    			newValue[0] = parseInt(value / fm) + ''
    		} else {
    			newValue[0] = parseFloat(value / fm).toFixed(2) + ''
    		}
    		newValue[1] = text1
    	}
    	if (value < 1000) {
    		newValue[0] = value + ''
    		newValue[1] = ''
    	}
    	return newValue.join('')
}


export { TimeFormat,NumberConversion }